<?php
$v_status_compare = 0;	
if(onegate_is_approve_leader_for_recordtype($v_staff_id,$_SESSION['onegate_current_recordtype'],$_SESSION["recordtype"])){
	$v_status_compare = 1;	
}
// Luu dieu kien loc theo linh vuc 
$v_current_item_id = '';
if(isset($_REQUEST['hdn_current_item_id'])){
	$v_current_item_id = $_REQUEST['hdn_current_item_id'];
}
if ($v_receive_date !=""){
	$v_receive_date_filter = $v_receive_date;
}else{
	$v_receive_date_filter = "";
}
if(isset($_REQUEST['hdn_received_date_filter'])){
	$v_receive_date_filter = $_REQUEST['hdn_received_date_filter'];
} 
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
$v_staff_id =  $_SESSION['staff_id'];
if (!isset($_SESSION['staff_id'])||is_null(($_SESSION['staff_id']))){
	$v_staff_id = 0;
}
$v_order_clause = '';

$v_fields='';
$v_values='';
if(isset($_REQUEST['ma_ho_so'])&&($_REQUEST['ma_ho_so']!='')) {
	$v_code .= $_REQUEST['ma_ho_so'];
}
if(isset($_REQUEST['ho_ten'])&&($_REQUEST['ho_ten']!='')) {
	$v_values .= $_REQUEST['ho_ten'];
}
//==========Dat bo sung tim theo cmnd
if(isset($_REQUEST['cmnd_hochieu'])&&($_REQUEST['cmnd_hochieu']!='')) {
	$v_id_card .= $_REQUEST['cmnd_hochieu'];
}
//===========================================
//==========Dat bo sung tim theo ten bang hieu
if(isset($_REQUEST['shop_name'])&&($_REQUEST['shop_name']!='')) {
	$v_shop_name .= $_REQUEST['shop_name'];
}
//===========================================
//==========Dat bo sung tim theo ten can bo thu ly
if(isset($_REQUEST['handler_name'])&&($_REQUEST['handler_name']!='')) {
	$v_handler_name .= $_REQUEST['handler_name'];
}
//===========================================
if(isset($_REQUEST['tu_ngay'])&&($_REQUEST['tu_ngay']!='')) {
	$v_from_date .= $_REQUEST['tu_ngay'];
}
if(isset($_REQUEST['den_ngay'])&&($_REQUEST['den_ngay']!='')) {
	$v_to_date .= $_REQUEST['den_ngay'];
}
//Leav_13112008_begin
if(isset($_REQUEST['dai_dien_a'])&&($_REQUEST['dai_dien_a']!='')) {
	$dai_dien_a =$_REQUEST['dai_dien_a'];
}
if(isset($_REQUEST['dai_dien_b'])&&($_REQUEST['dai_dien_b']!='')) {
	$dai_dien_b = $_REQUEST['dai_dien_b'];
}
//echo 'dai_dien_b'.$dai_dien_a.'<br/>';
//echo 'dai_dien_b'.$dai_dien_b.'<br/>';
//Leav_13112008_end

if ($v_is_granted_view_record){
	$v_role = "";
}
$v_status_of_handover = -10;
$v_status_of_assigning = -10;
$v_status_of_handle_approve = -10;
$v_status_of_chaiman_approve = -10;

$v_order_clause .= " ORDER BY C_RECEIVED_DATE ASC";
//Kiem tra co phai la module APPROVING hay khong va detail_status la rong

$v_receive_date_filter = "";
//Lay so dong tren mot danh sach
$v_limit_row = _CONST_NUMBER_OF_ROW_PER_LIST;
//session_start();
//$_SESSION['v_session_limit_num_page'] = $v_limit_row;
if(isset($_REQUEST['hdn_record_number_page'])&&$_REQUEST['hdn_record_number_page']!=""){
	$v_limit_row = $_REQUEST['hdn_record_number_page'];
	//$_SESSION['v_session_limit_num_page'] = $v_limit_row;
}

//Lay trang thu x
$v_page = 1;
//session_start();
//$_SESSION['v_session_page'] = $v_page;
//-----------19_01_09--------------------
if(isset($_REQUEST['sel_page'])&&$_REQUEST['sel_page']!=""){
	$v_page=$_REQUEST['sel_page'];	
	//$_SESSION['v_session_page'] = $v_page;
}
//-----------------------------------------
if(_is_sqlserver()){
	$v_recordtype_filter_ = $v_recordtype_filter;
	if($v_recordtype_filter=="All")
		for($i=0;$i<sizeof($arr_all_recordtype);$i++)
			if($i==0) $v_recordtype_filter_ = $arr_all_recordtype[$i][0];
			else $v_recordtype_filter_ .= ','.$arr_all_recordtype[$i][0];

	//print_r($arr_all_record); echo'<br/>-----------------------------------------------------------------------------'; 
	$arr_all_record = searching($v_staff_id,$v_recordtype_filter_,$v_from_date,$v_to_date, $v_values, $v_id_card, $v_shop_name, $v_handler_name,$v_order_clause,$v_page,$v_limit_row,$v_code,$dai_dien_a,$dai_dien_b);
	//print_r($arr_all_record); 
	
	//Tong so ho so
	$v_total_record = $arr_all_record[0]['TOTAL_RECORD'];
	//So ho so tra ve 
	$v_count = sizeof($arr_all_record);
	for($i=0;$i<$v_count;$i++){
		$arr_all_record[$i]['C_RECEIVED_RECORD_XML_DATA'] = stripslashes($arr_all_record[$i]['C_RECEIVED_RECORD_XML_DATA']);
		$arr_all_record[$i]['C_LICENSE_XML_DATA'] = stripslashes($arr_all_record[$i]['C_LICENSE_XML_DATA']);
	}
}
?>

<script>
	
	document.forms(0).ma_ho_so.value='<? echo $v_code;?>';
	document.forms(0).ho_ten.value='<? echo $v_values;?>';
	document.forms(0).cmnd_hochieu.value='<? echo $v_id_card;?>';
	document.forms(0).shop_name.value='<? echo $v_shop_name;?>';
	document.forms(0).handler_name.value='<? echo $v_handler_name;?>';
	document.forms(0).tu_ngay.value='<? echo $v_from_date;?>';
	document.forms(0).den_ngay.value='<? echo $v_to_date;?>';
	
	function clear_all(){
		document.forms(0).ma_ho_so.value='';
		document.forms(0).ho_ten.value='';	
		document.forms(0).dai_dien_a.value='';
		document.forms(0).dai_dien_b.value='';
		document.forms(0).cmnd_hochieu.value='';
		document.forms(0).shop_name.value='';
		document.forms(0).handler_name.value='';
		document.forms(0).tu_ngay.value='';
		document.forms(0).den_ngay.value='';
	}
</script>